package com.ruoyi.web.controller.company;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.user.Company;
import com.ruoyi.web.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/company")
public class CompanyController extends BaseController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/list")
    public TableDataInfo list(Company company) {
        startPage();
        List<Company> list = companyService.selectPageWithUsers(company);
        return getDataTable(list);
    }

    @GetMapping(value = "/{company}")
    public AjaxResult getInfo(@PathVariable Long company) {
        return AjaxResult.success(companyService.getById(company));
    }

    @GetMapping(value = "/user/{user}")
    public AjaxResult getInfoByUser(@PathVariable Long user) {
        return AjaxResult.success(companyService.getByUserId(user));
    }
}